<template>
  <div ref="chart" class="col"></div>
</template>

<script>
import echarts from 'echarts';

export default {
  components: {},
  props: {
  },
  data() {
    return {
      chart: null,
      theme: 'light',
    };
  },
  watch: {},
  computed: {},
  methods: {
    renderChart() {
      if (!this.chart && this.$refs.chart) {
        this.chart = echarts.init(this.$refs.chart, this.theme);
      }
      const option = this.getOptions();
      this.chart.clear();
      this.chart.setOption(option);
      setTimeout(() => {
        this.chart.resize();
      }, 100);
    },
    getOptions() {
      return {
        legend: {
          right: 'right',
        },
        series: [
          {
            name: '支出占比',
            type: 'pie',
            radius: ['30%', '90%'],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8,
            },
            data: [
              { value: 40, name: '工资' },
              { value: 38, name: '水电' },
              { value: 32, name: '燃料' },
              { value: 30, name: '其他' },
            ],
          },
        ],
      };
    },
  },
  created() { },
  mounted() {
    this.renderChart();
  },
};
</script>
<style lang="stylus"></style>
